package ink.metoo.gude.module.file.model

enum class FileCatalog(
    val parent: FileCatalog? = null,
    private val path: String,
) {
    USER(path = "u"),
    USER_AVATAR(parent = USER, path = "{uid}/avatar/{filename}"),
    ;

    val completePath: String = run {
        var cp = path
        var parent = parent
        while (parent != null) {
            cp = parent.path + "/" + path
            parent = parent.parent
        }
        return@run cp
    }

    fun fill(vararg pairs: Pair<String, String>): String {
        var completePath = completePath
        pairs.forEach {
            completePath = completePath.replace("{${it.first}}", it.second)
        }
        return completePath
    }

}